package com.chen.filters;

import javax.servlet.*;
import java.io.IOException;

public class LifeCycleFilter implements Filter {
    public LifeCycleFilter() {
        System.out.println("构造方法执行了");
    }

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("init 执行了");
        // 自动将web.xml中配置的属性注入到filterConfig中
        System.out.println(filterConfig.getInitParameter("key"));
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("doFilter 执行了");
        filterChain.doFilter(servletRequest, servletResponse);
    }

    @Override
    public void destroy() {
        System.out.println("destroy 执行了");
    }
}
